package com.huashizhaoxi.lionapp.dao;

import com.huashizhaoxi.lionapp.entity.FruitOrderChild;
import com.huashizhaoxi.lionapp.entity.FruitOrderMain;
import com.huashizhaoxi.lionapp.entity.complexType.FruitOrderComplexType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FruitOrderMapper {

    @Insert("insert into fruit_order_main (order_id ,user_id, total_price, order_status, create_time, receiver_name, receiver_phone, receiver_address, user_address_id, rider_id, mention, chopsticks) values (#{order_id} ,#{user_id}, #{total_price}, #{order_status}, #{create_time}, #{receiver_name}, #{receiver_phone}, #{receiver_address}, #{user_address_id}, #{rider_id}, #{mention}, #{chopsticks})")
    void addFruitMainOrder(FruitOrderMain fruitOrderMain);

    int addFruitChildOrder(List<FruitOrderChild> fruitOrderChild);

    @Select("select * from fruit_order_main where order_status = 2 ORDER BY create_time ASC")
    List<FruitOrderMain> getValidFruitOrder();

    @Select("select * from fruit_order_child where order_id = #{id}")
    List<FruitOrderChild> getFruitOrderChildList(int id);

    @Select("select * from fruit_order_child foc join fruit_buy fb on foc.product_id = fb.id where order_id = #{id}")
    List<FruitOrderComplexType> getFruitOrderComplexTypeList(int id);

    @Update("update fruit_order_main set order_status = #{state} where order_id = #{orderNo}")
    void changeState(String orderNo, int state);
}
